using System;
using System.Web.UI;

namespace Sedna.Core.Controller.Configurations
{
    /// <summary>
    /// Summary description for StringFormatDataGridColumnDataTranslator.
    /// </summary>
    public class DebitCreditDataTranslator : IDataTranslator
    {
        private string format = "{0:0.00##}";
        private bool isDebit=false;

        public string Format
        {
            get { return format; }
            set { format = value; }
        }
        public bool IsDebit
        {
            get { return isDebit; }
            set { isDebit = value; }
        }

        public object Translate(Control control, object value)
        {
            
            return Translate(control, value, null);
        }

        public object Translate(Control control, object value, Type targetType)
        {

            decimal res = Convert.ToDecimal(value);
                if (res < 0)
                {
                    return (isDebit)?String.Format(format, Math.Abs(res)):null;
                }
                else
                {
                    return (!isDebit) ? String.Format(format, Math.Abs(res)) : null;
                }
            
            
        }
    }
}
